import * as vscode from 'vscode';
import {dedent} from "../../../utils";

// documentation中使用了代码块，代码块中写的事makedown格式，首行不能为空
let spineAnimItems = [
    {
        "label": "SpineAnim_Create",
        "insertText": dedent`
        GUI:SpineAnim_Create(\${1:parent}, \${2:"Spine_1"}, \${3:200}, \${4:100}, \${5:"res/custom/nandaoshi/nandaoshi.json"}, \${6:"res/custom/nandaoshi/nandaoshi.atlas"}, \${7:1}, \${8:"animation"}, \${9:true})
        `,
        "documentation": dedent`# 创建Spine动画
        ## SpineAnim_Create(parent, ID, x, y, jsonPath, atlasPath, trackIndex, name, loop)

        | 参数       | 必选 | 类型    | 注释          |
        | :--------- | :--- | :------ | :------------ |
        | parent     | 是   | obj     | 父节点对象    |
        | ID         | 是   | string  | 唯一ID        |
        | x          | 是   | int     | 位置 横坐标   |
        | y          | 是   | int     | 位置 纵坐标   |
        | jsonPath   | 是   | string  | json文件路径  |
        | atlasPath  | 是   | string  | atlas文件路径 |
        | trackIndex | 是   | int     | 索引值        |
        | name       | 是   | string  | 动画名        |
        | loop       | 是   | boolean | 动画是否循环  |

        - 示例代码
        示例资源： [nandaoshi.zip](http://engine-doc.996m2.com/server/index.php?s=/api/attachment/visitFile&sign=09c2fd9bddb3643207257448ff81e6d7)

        \`\`\`
        GUI:SpineAnim_Create(GUI:Attach_LeftBottom(), "Spine_1", 200, 100, "res/custom/nandaoshi/nandaoshi.json", "res/custom/nandaoshi/nandaoshi.atlas", 1, "animation", true)
        \`\`\`
        `
    }
]



export function getCompletionItems(): vscode.CompletionItem[] {


    const completionItems: vscode.CompletionItem[] = [];
    spineAnimItems.forEach((item: any) => {
        completionItems.push(createFunctionCompletionItem(item.label, item.insertText, item.documentation));
    });
    return completionItems;
}

function createFunctionCompletionItem(label: string, insertText: string, documentation?: string): vscode.CompletionItem {
    const item = new vscode.CompletionItem(label, vscode.CompletionItemKind.Function);
    item.insertText = new vscode.SnippetString(insertText);
    if (documentation) {
        item.documentation = new vscode.MarkdownString(documentation);
    }
    return item;
}
